/***
 * 点击关闭 
 */
const { ccclass, property } = cc._decorator;

@ccclass
export class TouchRemove extends cc.Component {

    private _btn: cc.Button = null;

    public onLoad(): void {
        var clickEventHandler = new cc.Component.EventHandler();
        clickEventHandler.target = this.node; //这个 node 节点是你的事件处理代码组件所属的节点
        clickEventHandler.component = "TouchRemove";//这个是代码文件名
        clickEventHandler.handler = "onTouchThisButtonListener";
        clickEventHandler.customEventData = "Touch_Remove";

        this._btn = this.node.getComponent(cc.Button);
        this._btn.clickEvents.push(clickEventHandler);
    }

    public onEnable(): void {

        this.node.stopAllActions();

        cc.tween(this.node)
            .sequence(cc.delayTime(2.5), cc.removeSelf());
    }

    public onTouchThisButtonListener(evt: cc.Event, data: string): void {
        if (data != 'Touch_Remove') return;

        cc.tween(this.node)
            .sequence(cc.delayTime(0.5), cc.removeSelf());
    }

}
